package FSMDE.models.tests;

import java.util.UUID;

import junit.framework.Assert;

import main.java.FSMDE.models.Component;
import main.java.FSMDE.models.ComponentType;
import main.java.FSMDE.models.Interface;
import main.java.FSMDE.models.InterfaceGraphType;
import main.java.FSMDE.models.InterfaceType;

import org.junit.Test;


public class InterfaceTestCase {

	@Test
	public void testCreatingInterfaceSetsId() {
		Interface interface1 = new Interface("TestName", InterfaceType.General,
				InterfaceGraphType.Normal);
		Interface interface2 = new Interface("TestName1",
				InterfaceType.General, InterfaceGraphType.Normal);

		Assert.assertTrue(interface1.getId() instanceof UUID);
		Assert.assertTrue(interface2.getId() instanceof UUID);
		Assert.assertNotSame(interface1.getId(), interface2.getId());
	}

	@Test
	public void testCreatingInterfaceSetsTypes() throws Exception {
		Interface interface1 = new Interface("TestName", InterfaceType.General,
				InterfaceGraphType.Normal);
		Assert.assertSame(interface1.getType(), InterfaceType.General);
		Assert.assertSame(interface1.getGraphType(), InterfaceGraphType.Normal);

		interface1 = new Interface("TestName", InterfaceType.Entry_form,
				InterfaceGraphType.Starting_interface);
		Assert.assertSame(interface1.getType(), InterfaceType.Entry_form);
		Assert.assertSame(interface1.getGraphType(),
				InterfaceGraphType.Starting_interface);

		interface1 = new Interface("TestName", InterfaceType.Output_form,
				InterfaceGraphType.Starting_interface);
		Assert.assertSame(interface1.getType(), InterfaceType.Output_form);
		Assert.assertSame(interface1.getGraphType(),
				InterfaceGraphType.Starting_interface);

		interface1 = new Interface("TestName", InterfaceType.Menu_context,
				InterfaceGraphType.Ending_interface);
		Assert.assertSame(interface1.getType(), InterfaceType.Menu_context);
		Assert.assertSame(interface1.getGraphType(),
				InterfaceGraphType.Ending_interface);
	}

	@Test
	public void testComponentAddAndRemoveToInterface() {
		Interface interface1 = new Interface("TestName", InterfaceType.General,
				InterfaceGraphType.Normal);

		Component button1 = Component.create("TestName", ComponentType.Button);
		Component button2 = Component.create("TestName2", ComponentType.Button);
		Component section = Component.create("TestName3", ComponentType.Form);
		Component list = Component.create("TestName4",
				ComponentType.Unsorted_List);

		interface1.getComponents().add(button1);
		Assert.assertEquals(1, interface1.getComponents().count());
		interface1.getComponents().add(button2);
		Assert.assertEquals(2, interface1.getComponents().count());
		interface1.getComponents().add(section);
		Assert.assertEquals(3, interface1.getComponents().count());
		interface1.getComponents().add(button2);
		Assert.assertEquals(3, interface1.getComponents().count());
		interface1.getComponents().add(list);
		Assert.assertEquals(4, interface1.getComponents().count());

		interface1.getComponents().remove(list);
		Assert.assertEquals(3, interface1.getComponents().count());
		interface1.getComponents().remove(button1);
		Assert.assertEquals(2, interface1.getComponents().count());
		interface1.getComponents().remove(button1);
		Assert.assertEquals(2, interface1.getComponents().count());
	}
}
